package com.atguigu.gmall.product;

import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.util.ClassUtils;

public class FastDFSDemo {


    //文件上传
    public static void main(String[] args) throws Exception{
        //读取绝对路径 能读取target下的路径 但是第0步 本机无效
//        String path = ClassUtils.getDefaultClassLoader().getResource("fdfs_client.conf").getPath();
        //0:设置配置文件的位置进行读取  init IO流 读取配置文件 必须是绝对路径
//        ClientGlobal.init(path);
        //使用绝对路径
        ClientGlobal.init("D:\\WLin\\IntelliJ IDEA 2018.3.2\\Project\\gmall_sph\\gmall-parent\\service\\service-product\\src\\main\\resources\\fdfs_client.conf");
        //1:连接Tracker跟踪器/创建客户端???
        TrackerClient trackerClient = new TrackerClient();
        //2:返回值存储节点地址
        TrackerServer trackerServer = trackerClient.getConnection();
        //3:连接存储节点
        StorageClient1 storageClient1 = new StorageClient1(trackerServer,null);
        //4:上传文件
        String fileId = storageClient1.upload_file1(
                "C:\\Users\\Administrator\\Pictures\\Saved Pictures\\蛇矛.jpg",
                "jpg",
                null
        );
        System.out.println("http://192.168.6.137:8080/" + fileId);

    }
}
